function textareaPrepare() {
  var text = "";
  var words = $("#textarea").text().trim().split(" ");
  for(var j = 0; j < words.length; j++)
    text += " <span class=\"open\" id=\"" + (j+1) + "\">" + words[j] + "</span>";
  //var text = words.join("</span> <span id=\"" + (i++) +"\">");
  $("#textarea").html(text);
}

function getSelected() {
  if(window.getSelection) {
    return window.getSelection();
  }
  else if(document.getSelection) {
    return document.getSelection();
  }
  else {
    var selection = document.selection && document.selection.createRange();
    if(selection.text) {
      return selection.text;
    }
    return false;
  }
  return false;
}
jQuery.fn.idElement = function() {
  $(this).attr("id", ($(this).attr("id") - 1));

  return this;
}